package com.ysd.modules.sys.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ysd.common.utils.R;
import com.ysd.modules.sys.entity.PaperInfo;
import com.ysd.modules.sys.entity.TestPaper;
import com.ysd.modules.sys.entity.Topic;
import com.ysd.modules.sys.service.PaperInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author dapeng
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/sys/paperInfo")
public class PaperInfoController {
    @Autowired
    private PaperInfoService paperInfoService;

    @PostMapping("/autoPaper")
    public R autoPaper(@RequestBody List<Map<String, Object>> objs) {
        R ok = R.ok();
        boolean b = paperInfoService.autoPaper(objs);
        ok.put("res", b);
        return ok;
    }

    @GetMapping("/getTopicListByTid")
    public R getTopicListByTid(Integer tid, Integer page, Integer limit) {
        IPage<PaperInfo> paperInfoIPage = paperInfoService.getTopicListByTid(tid, page, limit);
        R ok = R.ok();
        ok.put("data", paperInfoIPage.getRecords());
        ok.put("count", paperInfoIPage.getTotal());
        return ok;
    }

    @GetMapping("/delPaperInfo")
    public R delPaperInfo(Integer id, Integer tid) {
        boolean res = paperInfoService.delPaperInfo(id, tid);
        R ok = R.ok();
        ok.put("res", res);
        return ok;
    }

    @GetMapping("/addPaperInfo")
    public R addPaperInfo(Integer pid, Integer tid) {
        boolean res = paperInfoService.addPaperInfo(pid, tid);
        R ok = R.ok();
        ok.put("res", res);
        return ok;
    }
}

